package com.easy;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Lxk on 2020/2/21.
 */
public class Solution383 {

    public boolean canConstruct(String ransomNote, String magazine) {
        Map<Character, Integer> chCountMap = new HashMap<>();
        for (Character ch : magazine.toCharArray()) {
            if (chCountMap.keySet().contains(ch)) {
                chCountMap.put(ch, chCountMap.get(ch) + 1);
            } else {
                chCountMap.put(ch, 1);
            }
        }

        for (Character ch : ransomNote.toCharArray()) {
            if (chCountMap.containsKey(ch)) {
                chCountMap.put(ch, chCountMap.get(ch) - 1);
            } else {
                return false;
            }
        }

        for (Map.Entry<Character, Integer> entry : chCountMap.entrySet()) {
            if (entry.getValue() < 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution383 solution383 = new Solution383();
        System.out.println(solution383.canConstruct("aa", "aab"));
    }

}
